package Model;


public class Square 
{
	// ATTRIBUTE
	private Location location;
	private SquareType type;
	private Being beingReference;
	private Building buildingReference;
	private Resource resource;

	// CONSTRUCTOR
    public Square(Location location, SquareType type) 
    {
        this.location = location;
        this.type = type;
        this.beingReference = null;
        this.buildingReference = null;
        this.resource = null;
    }

	
	
	// OWN FUNCTIONS
	public void displayShortInfoInTerminal()
	{
		System.out.print("x = " + this.location.getXPosition());
		System.out.println(" y = " + this.location.getYPosition());
		
	}
	
	public void displayLongInfoInTerminal()
	{
                System.out.println("Square Display Information :");
                System.out.print("Location : ");
		System.out.print("x = " + this.location.getXPosition());
		System.out.println(" y = " + this.location.getYPosition());
		if ( type != null )
		{
			System.out.println("Type : " + type);
		}
		if ( beingReference != null )
		{
                        System.out.println("Being on the square infos : ");
			beingReference.displayInfoInTerminal();
		}
		if ( resource != null )
		{
                        System.out.println("Resource : ");
			resource.displayInTerminal();
		}
		
	}
	
	public String toString()
	{
		String symb = "";
		switch ( this.type )
		{
			case Plain :
				symb = ".";
				break;
			case Wood :
				symb = "|";
				break;
			case Water :
				symb = "O";
				break;
			case Gold :
				symb = "g";
				break;
			case Stone :
				symb = "s";
				break;
			case Mountain :
				symb = "M";
				break;
		}
		
		Being b = this.beingReference;
		if ( b != null )
		{
			if ( b.isAnimal() )
				symb = "A";
			else
				symb = "H";
		}
		
		return symb;
	}
       
        
     
    public boolean isObstacle() 
    {
        boolean isObstacle = false;
        
        if ( this.beingReference != null || this.buildingReference != null ) 
        {
            isObstacle = true;
        } 
        
        switch ( this.type ) 
        {
            case Gold:
            case Stone:
            case Mountain:
            case Water:
                isObstacle = true;
                break;
        }

        return isObstacle;
    }
        
    // CONSTRUCTOR
	
	// GETTER - SETTER
	public Resource getResource() 
	{
		return resource;
	}

	public Location getLocation()
	{
		return this.location;
	}
	
	public SquareType getType()
	{
		return this.type;
	}
	
	public Being getBeingReference()
	{
		return this.beingReference;
	}
	
	public Building getBuildingReference()
	{
		return this.buildingReference;
	}
	
	public void setResource(Resource newResource) 
	{
		this.resource = newResource;
	}
	
	
	public void setType(SquareType newType)
	{
		this.type = newType;
	}
	
	public void setBeingReference(Being newBeingReference)
	{
		this.beingReference = newBeingReference;
	}
	
	public void setBuildingReference(Building newBuildingReference)
	{
		this.buildingReference = newBuildingReference;
	}
        
        public void removeBeing() {
            this.beingReference = null;
            if(this.beingReference != null) {
                System.out.println("Failed to remove being :");
                this.getBeingReference().displayInfoInTerminal();
                System.out.append("From square : ");
                this.getLocation().displayInTerminal();
            }
        }

}
